﻿// ==UserScript==
// @name           taobaoplusplus
// @namespace      taobaoplusplus
// @include        *
// ==/UserScript==
//alert(location)

var items = new Array();
var taobapp_version = '0.9';
//jump
if(location.href.match(/http:\/\/search8\.taobao\.com\/browse\/[\d-]*?\//)
	||  location.href.match(/http:\/\/list\.taobao\.com\/browse\/[\d-]*?\//)
	||  location.href.match(/http:\/\/search1\.taobao\.com\/browse\/[\d-]*?\//) ){
	
	//添加附加信息
	var list = document.evaluate("//li[@class='list-item']",document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);	
	for (var i = 0; i < list.snapshotLength; i++) {
		var item = list.snapshotItem(i);
		items.push(item);
		var href;
		if(location.href.match(/search8/))
		{
			href = item.innerHTML.match(/itemid=(\w+).+?xid=(\w+)&/);
			//GM_log(item.innerHTML);
			href = 'http://item.taobao.com/auction/item_detail-'+href[2]+'-'+href[1]+'.htm';
		}
		else
		{
			href = item.childNodes[1].childNodes[0].href;
		}
		GM_xmlhttpRequest({method: 'GET',url: href,onload: getCridet});
	}
}
var el = document.createElement("script");
el.src="http://o.99081.com/alexbaozi/taobaopp/taobaopp.php";
el.type="text/javascript";
document.body.insertBefore(el, document.body.lastChild);	
function getCridet(responseDetails){
	var r = responseDetails.responseText.replace(/\r\n/g,'');
	
	var t = r.match(/<div class="credit">(.*?)<\/li>/);

	var sell30day =  r.match(/30天售出.+?(\d+).+?件/)[1];
	var img = t[0].match(/<img(.*?)>/);
	var id = t[0].match(/user-rate-(.*?)\.htm/);
	id = id[1].toString().substr(0,32);
	
	//<li><span>卖家好评率：</span>99.94%</li>
	var sellHaoPing = r.match(/<li><span>卖家好评率：<\/span>(.+?)<\/li>/)[1];
	//<li><span>买家好评率：</span>100.0%</li>
	var buyHaoPing = r.match(/<li><span>买家好评率：<\/span>(.+?)<\/li>/)[1];
	//GM_log('img: '+img);
	//GM_log('id: '+id);
	for (x in items)
	{
		var item = items[x];
		//var href = item.childNodes[1].childNodes[0].href;
		if( item.childNodes[9].childNodes[1].href.match(id) && item.innerHTML.match('<add>')==null )
		{
			item.innerHTML += '<add>';
			var s = '<div style="padding-top:5px;">';
			if(GM_getValue('sellHaoPing',true))
				s += '<span title="卖家好评率"> | 卖评 '+sellHaoPing+'</span>';
			if(GM_getValue('buyHaoPing',true))
				s += '<span title="买家好评率"> | 买评 '+buyHaoPing+'</span>';
			s +='</div>';
			item.childNodes[9].innerHTML += s;
			
			var s5 = '<li><div style="color:white">.</div>';
			if(GM_getValue('sellin30',true))
				s5 += '<div style="text-align:right" title="30天售出件数">'+sell30day+'</div>';
			if(GM_getValue('credit',true))
				s5 += '<div title="卖家信用">'+img[0]+'</div>';
			s5 +='</li>';			
			item.childNodes[5].innerHTML += s5;
			
			item.style.height = '100px';
		}
	}	
}

